package com.lww.smartbathroom.control;

import com.lww.smartbathroom.service.EquipmentService;
import com.lww.smartbathroom.service.UserRecordService;
import com.lww.smartbathroom.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 刘正星
 * @version 1.0.0
 * @ClassName BackendController.java
 * @Description TODO
 * @createTime 2021年01月31日 19:14:00
 */
@Controller
public class BackendController {

    @Autowired
    private EquipmentService equipmentService;

    @Autowired
    private UserService userService;

    @Autowired
    private UserRecordService userRecordService;

    @GetMapping("/backendLogin")
    public  String backendLogin(){
        return "backend-login";
    }

    @GetMapping("/backend")
    public  String backend(){
        return "backend";
    }
    @GetMapping("/back")
    public  String back(){
        return "back";
    }

    @GetMapping("/user-list")
    public  String userList(){
        return "views/user-list";
    }

    @GetMapping("/order-list")
    public  String orderList(){
        return "views/order-list";
    }

    @GetMapping("/equipment-list")
    public  String equList(){
        return "views/equipment-list";
    }


    @GetMapping("/welcome")
    public  String welcome(Model model){
        Map map = new HashMap();
        map.put("epuipmentCount",equipmentService.count());
        map.put("userCount",userService.count());
        map.put("record",userRecordService.count());
        map.put("totalPrice",userRecordService.tatalPrice());
        long viewCount = equipmentService.count();
        viewCount++;
        map.put("viewCount",viewCount);
        model.addAttribute("map",map);
        return "views/welcome";
    }
}
